<?php
/**
 * @file bg2.php
 * @package taobaoke
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-7-23 下午01:04:56 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * 发布Post的AJAX后端
 */
require_once 'lib/functions.php';
header("Content-Type:text/html;charset=UTF-8");

$page_size = $_POST['page_size'];
$delicious = $_POST['delicious'];
$action = $_POST['action'];

if( $action == "postTaobaoItems" ){
	echo "<?xml version='1.0' encoding='utf-8'?>".
	"<items>";
	
	$ig = new tbkDB();
	for ($i=0; $i<$page_size; $i++){
		$postInfo = $ig->getItemRand();
		
		$postCategory = array(CATEGORY_YID, (int)$postInfo['sid']);
		if ((int)$postInfo['commission_num'] > 0){
			array_push($postCategory, CATEGORY_HID);
		}
		
		$exceprt = getExcerpt($postInfo['title2'], $postInfo['price'], $postInfo['desc']);
		$keywords = getKeywords($postInfo['title'], $postInfo['properties'], $postInfo['cname']);
		
		$post = array(
 			 'comment_status' => 'open', // 'closed' means no comments.
			 'ping_status' => 'closed', //Ping status?
			 'post_author' => '3',
			 'post_category' => $postCategory,
			 'post_content' =>  $postInfo['desc'],
			 'post_date' => date("Y-m-d H:i:s", mktime()+mt_rand(-15,15)*10800 ),
			 'post_excerpt' => $exceprt,
			 'post_name' => title2slug($keywords[0]),
			 'post_status' => 'publish',
			 'post_title' => $postInfo['title2'],
			 'post_type' => 'post',
			 'tags_input' => implode(',', $keywords),
			);
		$pID = wp_insert_post($post);
		$pLink =  get_permalink($pID);
		$metas = array();
		
		if (!empty($pID))
			echo "<item><title>{$postInfo['title2']}</title><link>{$pLink}</link></item>";
			
	} //for
	
	echo "</items>";
} //if action

?>